import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:堆排序
 * User: YJ
 * Date: 2024-4-06
 * Time: 15:15
 */
public class HeapSort {


    public HeapSort(int[] array) {
        //建立大顶堆
        MaxHeap maxHeap = new MaxHeap(array);

        while (maxHeap.size > 1) {
            //堆顶元素换到堆尾
            maxHeap.swap(array,0, maxHeap.size - 1);
            maxHeap.size --;
            maxHeap.nonRecursionDown(array,0);
        }
    }

    public static void main(String[] args) {
        int[] arr = new int[] {5,2,8,4,0,3};
        HeapSort heapSort = new HeapSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
